<template>
	<view>
		<view>昵称 <input v-model="nickName" /> </view>
		<view>头像
			<uni-file-picker ref="files" :auto-upload="false" />
		</view>
		<button @click="submit">确定修改</button>
	</view>
</template>

<script>
	import {
		uploadFile
	} from "../../service/homeService.js"
	import  {updateUser} from  "../../service/userService.js"
	export default {
		data() {
			return {
				nickName: "",
			}
		},
		methods: {
			async submit() {
				//this.$refs.files.upload();
				let file  = this.$refs.files.files[0];
				console.log(file);
				// let formData  = new  FormData();
				// formData.append("file",file);

				let res = await uni.uploadFile({
					url: "http://124.93.196.45:10001/prod-api/common/upload",
					header: {
						"Authorization": uni.getStorageSync("token")
					},
					file: this.$refs.files.files[0],
					filePath:this.$refs.files.files[0].path,
					name:"file"
				})
				console.log(res);
				let  data  =res.data;
				data = JSON.parse(data);
				 let fileName  = data.fileName;
				
				let  res2  = await updateUser({
					nickName:this.nickName,
					avatar:fileName
				})
				if(res2.data.code==200){
					uni.reLaunch({
						url:"/pages/mine/mine"
					})
				}
				
				

				// let  res  = await  uploadFile(formData);
				// console.log(res);

			}
		}
	}
</script>

<style>

</style>
